package cn.com.eado.crm.model.db

import androidx.lifecycle.LiveData
import androidx.room.*
import cn.com.eado.crm.m.db.EnterpriseInfo


@Dao
interface EnterpriseInfoDao {
    @Insert//(onConflict = OnConflictStrategy.REPLACE)
    fun insert(enterpriseInfo: EnterpriseInfo)

    @Insert//(onConflict = OnConflictStrategy.REPLACE)
    fun insert(enterpriseInfos: List<EnterpriseInfo>)

//    @Insert(onConflict = OnConflictStrategy.REPLACE)
//    fun replaceAll(enterpriseInfos: List<EnterpriseInfo>)

//    @Insert(onConflict = OnConflictStrategy.REPLACE)
//    fun replace(enterpriseInfo: EnterpriseInfo)

    @Delete
    fun delete(enterpriseInfo: EnterpriseInfo)

    @Delete
    fun delete(enterpriseInfos: List<EnterpriseInfo>)

    @Update
    fun update(enterpriseInfo: EnterpriseInfo)

    @Update
    fun update(enterpriseInfos: List<EnterpriseInfo>)

//    @Query("select * from enterprise_info")  //查询所有
//    fun queryAll(): LiveData<List<EnterpriseInfo>>

    @Query("select * from enterprise_info where userId = :userId")  //查询所有
    fun queryWithUser(userId: Int): LiveData<List<EnterpriseInfo>>?  //即使没有数据返回的也不少null，而是[]

    @Query("select * from enterprise_info where userId = :userId")  //查询所有
    fun queryWithUser2(userId: Int): List<EnterpriseInfo>?  //即使没有数据返回的也不少null，而是[]

    @Query("select * from enterprise_info where userId = :userId and department like '%' || :department || '%'")  //查询所有
    fun queryWithDepartment(userId: Int, department: String): LiveData<List<EnterpriseInfo>>?  //即使没有数据返回的也不少null，而是[]

}